package com.sc.pattern.guardedsuspension;

import java.util.LinkedList;

/**
 * Created  on 2018/1/7.
 *
 * @author sc
 */
public class RequestQueue {
    private final LinkedList<Request> queue = new LinkedList<>();

    public Request getRequest(){
        synchronized (queue) {
            while (queue.size()<=0){
                try {
                    queue.wait();
                } catch (InterruptedException e) {
                    break;
                }
            }
            return queue.removeFirst();
        }
    }
    public void putRequest(Request request){
        synchronized (queue){
            queue.addLast(request);
            queue.notifyAll();
        }
    }
}
